﻿using AutoMapper;
using MediatR;
using Message.Domain;
using Message.Infrstructre.Impl;
using WMSmessage.Api.Applcation.Command;

namespace WMSmessage.Api.Applcation.CommandHandlers
{
    /// <summary>
    /// 消息新增
    /// </summary>
    public class MessageCreateCommandHandlers : IRequestHandler<MessageCreateCommand, int>
    {
        protected readonly IbaseMessageRepsitory messRep;
        protected readonly IMapper mapper;

        public MessageCreateCommandHandlers(IbaseMessageRepsitory messRep, IMapper mapper)
        {
            this.messRep = messRep;
            this.mapper = mapper;
        }

        public async Task<int> Handle(MessageCreateCommand request, CancellationToken cancellationToken)
        {
            return await messRep.AddAsync(mapper.Map<Messageinfo>(request.dtos));
        }
    }
}
